import api from '@/utils/request';
import crypto from 'crypto';

// export function encode(str) {
//   const cipher = crypto.createCipher('aes192', 'deliveryIsen');
//   let crypted = cipher.update(str, 'utf8', 'hex');
//   crypted += cipher.final('hex');
//   return crypted;
// }

export function encode(str, secret) {
  const cipher = crypto.createCipher('aes192', secret);
  let crypted = cipher.update(str, 'utf8', 'hex');
  crypted += cipher.final('hex');
  return crypted;
}

export async function userLogin({ username, password }) {
  const result = await api.post('/api/user/login', {
    username,
    password,
  });
  return result;
}
export async function userRegist(data) {
  const result = await api.post('/api/user/regist', data);
  return result;
}

export async function changePassword({ oldPassword, newPassword }) {
  const result = await api.put('/api/user/changePassword', {
    oldPassword,
    newPassword,
  });
  return result;
}

export async function getUserInfo({ id }) {
  const result = await api.get('/api/user/userinfo', { params: { id } });

  return result;
}
